#pragma once
#ifndef __COMMON_HPP__
#define __COMMON_HPP__
#endif

#include <iostream>
#include <string>
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/ipc.h>
#include <sys/shm.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <string.h>
#include <time.h>

const std::string gpath = ".";
const mode_t gmode = 0600;

const int gprojId = 0x666;
const int gshmsize = 4096;
const int gsize = 1024;
std::string ToHex(key_t k)
{
    char buffer[64];
    snprintf(buffer, sizeof(buffer), "0x%x", k);
    return buffer;
}

std::string GetCurrentTime()
{
    time_t t = time(nullptr);

    std::cout << "pos 5" << std::endl;
    struct tm *curr = ::localtime(&t);
    std::cout << "pos 6" << std::endl;

    char currtime[32];
    snprintf(currtime, sizeof(currtime), "%d-%d-%d %d:%d:%d",
             curr->tm_year,
             curr->tm_mon,
             curr->tm_mday,
             curr->tm_hour,
             curr->tm_min,
             curr->tm_sec);
    return currtime;
}

struct Data
{
    char status[32];
    char lasttime[48];
    char image[4000];
};